import { joinURLParam } from "/@/utils";
import { http } from '/@/plugins/request';
import userAPI from './user';
import commodityAPI from './commodity';
import newsAPI from './news';
import callingCardAPI from './callingCard';

import config from '/@/config/index';
const baseUrl = config.baseUrl;

const apis = Object.assign(
  {},
  userAPI,
  commodityAPI,
  newsAPI,
  callingCardAPI
);

const generateApis = apiList => {
  const newApis = {};
  for (let key in apiList) {
    if (apiList[key].method == 'post') {
      newApis[key] = data => {
        return http.post(`${apiList[key].url}`, data);
      };
    } else {
      newApis[key] = data => {
        return http.get(`${apiList[key].url}` + joinURLParam(data));
      };
    }
  }

  return newApis;
};

export default generateApis(apis);
